package com.his.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.his.api.service.HospitalService;
import com.his.dao.domain.dto.ListDto;
import com.his.dao.domain.entity.Hospital;
import com.his.dao.domain.vo.ListVo;
import com.his.dao.mapper.HospitalMapper;
import com.his.util.result.RestResult;
import com.his.util.result.RestResultBuilder;
import com.his.util.util.MapUtil;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author fall
 * @since 2022-11-28
 */
@Service
@AllArgsConstructor
public class HospitalServiceImpl extends ServiceImpl<HospitalMapper, Hospital> implements HospitalService {
    private HospitalMapper hospitalMapper;

    @Override
    public RestResult all(ListDto listDto) {
        Hospital hospital = MapUtil.conversionMapToObj((Map) listDto.getObj(), Hospital.class);

        Page page = new Page(listDto.getPage(), listDto.getPageSize());
        QueryWrapper<Hospital> queryWrapper = new QueryWrapper<Hospital>()
                .like("name", hospital.getName());
        return new RestResultBuilder().success(hospitalMapper.selectPage(page, queryWrapper));
    }

    @Override
    public RestResult allId(Hospital hospital) {
        QueryWrapper<Hospital> queryWrapper = new QueryWrapper<Hospital>()
                .select("hospital_id", "name")
                .like(hospital.getName() != null, "name", hospital.getName());
        return new RestResultBuilder().success(hospitalMapper.selectList(queryWrapper));
    }
}
